<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>商场库</title>
        <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">

        <script src="http://i.gtimg.cn/qzone/biz/gdt/lib/jquery/jquery-2.1.4.js?max_age=31536000"></script>

        <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/webapp/js/common/config.js"></script>
        <script type="text/javascript" src="/webapp/js/common/cities.js"></script>
    </head>
    <body>
    	   <div class="easyui-container-fluid">
              <div class="easyui-panel" style="border: none;">
                 <div class="nav" id="nav"></div>
                 <div class="easyui-panel" style="border:none;">
                	<form id="ff">
                      <div style="margin-bottom:20px;">
                        <label class="item-label">商场代码：</label>
                        <input id="mallCode" type="text" class="easyui-textbox" name="code" style="width:100px;"/>
                        <label class="item-label">商场名称：</label>
                        <input type="text" class="easyui-textbox" name="name" style="width:100px;"/>
                        <label class="item-label">渠道：</label>
                        <select class="easyui-combobox" name="channelCode" id="channel" data-options="panelHeight:200" style="width:100px;">
                        </select>
                        <label class="item-label">状态：</label>
                          <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >
                        <label class="item-label">类型：</label>
                        <select class="easyui-combobox" id="mallType" name="type" data-options="panelHeight:'auto'" style="width:100px;">
                          <option value="">-请选择-</option>
                          <option value="SUPERMARKET">超市</option>
                          <option value="DEPARTMENT_STORE">百货</option>
                          <option value="PRO_SHOP">家电专营</option>
                          <option value="KA">全国家电连锁</option>
                          <option value="BUILDING_MATERIAL">建材</option>
                        </select>
                      </div>
                      <div style="margin-bottom:20px;">
                          <label class="item-label">省份：</label>
                          <select name="provinceCode" class="easyui-combobox" id="province" data-options="panelHeight:'auto'" style="width:100px;">
                          </select>
                          <label class="item-label">隶属城市：</label>
                          <select name="belongingCityCode" id="belongingCity" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                          </select>
                          <label class="item-label">市：</label>
                        <select class="easyui-combobox" name="cityCode" id="city" data-options="panelHeight:200" style="width:100px;">
                        </select>
                        <a class="easyui-linkbutton c8" style="width:80px;margin-left: 40px;" onclick="searchBy()">查询</a>
                        <a class="easyui-linkbutton c8" style="width:100px;margin-left: 40px;" onclick="searchCount()">查询销售数据</a>
                      </div>
                    </form>
                     <div id="upmall" class="easyui-window upload-wrapper" title="上传文件" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px;height:260px;padding:10px;">
                         <form id="file_form" action="" enctype="multipart/form-data"method="post">
                             <div style="margin-bottom:20px;margin-top: 20px;">
                                 <input type="file" multiple="multiple" name="file" id="file_input" class="item-label"style="margin-top: 33px;margin-left: 64px;width: 280px;" />
                             </div>
                             <div style="margin-bottom:20px;margin-top: 60px;text-align:center">
                                 <input type="button" value="文件上传" name="Submit" id='sub' style="height: 40px;width: 100px;font-size: 18px;" class="easyui-linkbutton c8">
                             </div>
                         </form>
                     </div>
                     <div id="displayxx" class="easyui-window upload-wrapper" title="上传结果" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:1200px;height: 430px;padding:10px;">
                         <div><li>信息为：</li><span id="messagetext"></span></div>
                         <div style="margin-left: 550px;"><button class="easyui-linkbutton c8" style="width: 100px;margin-top: 130px;" onclick="clickHandler()">确定</button></div>
                     </div>
                 </div>
                 <div class="table-wrapper">
                   <table id="datagrid" style="width:100%;" data-options="fitColumns:true,scrollbarSize:0">
                     <thead>
                       <tr>
                         <th data-options="field:'code',align:'center'" width="80">商场代码</th>
                         <th data-options="field:'name',align:'center'" width="120">商场名称</th>
                         <th data-options="field:'channelCode',align:'center'" width="80">渠道代码</th>
                         <th data-options="field:'channelName',align:'center'" width="130">渠道名称</th>
                         <th data-options="field:'provinceName',align:'center'" width="80">省份</th>
                         <th data-options="field:'cityName',align:'center'" width="80">市</th>
                         <th data-options="field:'belongingCityName',align:'center'" width="80">隶属城市</th>
                         <th data-options="field:'type',align:'center',formatter:typeFormatter" width="80">类型</th>
                         <th data-options="field:'shopCount',align:'center'" width="80">门店数</th>
                         <th data-options="field:'countent',align:'center'" width="160">包含商场</th>

                         <th data-options="field:'remark',align:'center'" width="160">备注</th>
                         <th data-options="field:'operateUsername',align:'center'" width="80">操作人</th>
                         <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="80">状态</th>
                         <th data-options="field:'action',align:'center',formatter:actions" width="160">操作</th>
                       </tr>
                     </thead>
                     <tbody>
                     </tbody>
                   </table>
                 </div>
              </div>
         </div>
    </body>
    <script type="text/javascript">
        $(function(){
            initChannelSelect("channel");
            initCityCombobox("city");
            initProvinceCombobox('province', "", "belongingCity");
            $("#city").combobox("setValue",{text:"-请选择-",value:""});
            // $("#belongCity").combobox("setValue",{text:"-请选择-",value:""});
            var height = $(window).height();
            var nav_height = $("#nav")._outerHeight();
            var ff_height = $("#ff").height();
            var table_height = height-nav_height-ff_height-40;
            $("#datagrid").css("max-height",table_height);
            $("#datagrid").datagrid({
               toolbar:[{
                    text:'添加商场',
                    handler:function(){
                      window.parent.addTab("添加商场","/webapp/pages/channel/mall/add.html");
                    }
                },'-',{
                   text:'上传商场',
                   handler:function(){
                       $("#upmall").window("open");
                   }
               }]
           })
            if("online"==window.parent.workMode){
                $("#mallType").combobox({
                    data:[
                        {text:"-请选择-",value:""},
                        {text:"专业电商",value:"SPECIALTY_EB"},
                        {text:"平台电商",value:"PLATFORM_EB"}
                    ]
                });
            }
        });
        function typeFormatter(type){
           var res = "";
           switch(type){
             case "SUPERMARKET":
                res = "超市";
                break;
             case "DEPARTMENT_STORE":
                res="百货";
                break;
             case "PRO_SHOP":
                res="家电专营";
                break;
             case "KA":
            	 res="全国家电连锁";
            	 break;
               case "BUILDING_MATERIAL":
                   res="建材";
                   break;
             case "SPECIALTY_EB":
                res="专业电商";
                break;
             case "PLATFORM_EB":
                res="平台电商";
                break;
             default:
                res="超市";
           }
           return res;
        }
        /*上传文件from的方式*/
        $(function() {
            $("#sub").click(function () {
                // var form = new FormData(document.getElementById("file_form"));
                // alert(form);
                $("#file_form").ajaxSubmit({
                    xhrFields:{withCredentials:true},
                    url:config.url +"/mall/mallUpload",
                    type:"POST",
                    dataType : "json",
                    data:$('#file_form').serialize(),
                    processData: false,
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:20,
                            text:"操作进行中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                    },
                    success : function(data) {
                        if(data.code=="200"){
                            $("#displayxx").window("open");
                            document.getElementById("messagetext").innerText=data.msg;
                            // alert(data.msg);
                        }
                    }
                })
            })
        });
        function clickHandler() {
            // alert("onclick attribute in html");
            $("#displayxx").window("close");
            $("#upmall").window("close");
            searchBy();
        }
    </script>
    <script type="text/javascript" src="/webapp/js/common/pagelist.js"></script>
    <script type="text/javascript">

        $(function () {
            setNav();
            aRecords("商场管理","/webapp/pages/channel/mall/")
        });
        function edit(id) {
            window.parent.addTab("修改商场","/webapp/pages/channel/mall/add.html?id="+id);
        }

        function searchCount() {
            var code = $("#mallCode").val();
            if(code){
                $.ajax({
                    url:config.url+"/mall/searchDataCount",
                    type:'get',
                    xhrFields:{withCredentials:true},
                    data:{mallCode:code},
                    dataType:"json",
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"数据加载中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                    },
                    success:function(data){
                        $.messager.progress("close");
                        if (data.code == "200") {
                            $.messager.alert("提示",data.msg,"info");
                        }else {
                            $.messager.alert("提示",data.msg,"error");
                        }
                    },
                    error:function(XMLHttpRequest,textStatus,thrown){
                        $.messager.progress("close");
                    }
                });
            }else {
                $.messager.alert("提示","请输入商场码","error");
            }

        }
    </script>
</html>